<template>
  <div>
    <data-table :head="thead1" :data="specialTask" :page='currentPage' @callback="manipulate" :actions="['edit','del']"
                class="intendance-table"></data-table>
    <i class="el-icon-circle-plus-outline add-icon" @click="addTask"></i>
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                   :current-page.sync="currentPage" layout="total,prev, pager, next, jumper"
                   :total="totalnum1" background>
    </el-pagination>

  </div>
</template>

<script>
  import DataTable from '@/components/common/DataTable.vue'
  import plansService from '@/services/PlansService.js'

  export default {
    props: ['specialTask', 'totalnum1'],
    name: 'SpecialTask',
    components: {
      'data-table': DataTable
    },
    data: function () {
      return {
        level1: -1,
        level2: -1,
        dlevel1: -1,
        dlevel2: -1,
        mlevel1: -1,
        mlevel2: -1,
        detail: '',
        thead1: [{name: '专项名称', prop: 'name'}],
        tableData1: [],
        leveldialog: false,
        lvform: {
          level1: '',
          name: '',
        },
        toptions: [],
        croptions: [],
        currentPage: 1,
        totalPage1: 0,
        mltitle: '添加巡航里程',
      }
    },
    mounted () {
      this.getData
    },
    methods: {
      getData (num) {

      },
      lvbtn () {
        if (!this.lvform.level1) {
          this.$alert('请选择一级任务类型')
          return false

        }
        if (!this.lvform.name) {
          this.$alert('请输入二级任务名称')
          return false
        }
        this.$axios.get('TaskTypeAddTaskType', {
          params: {
            skey: localStorage.getItem('auth'),
            pid: this.lvform.level1,
            name: this.lvform.name,
            level: 2,

          }
        }).then((res) => {
          if (res.data.errno == '100100') {
            this.$alert('添加成功').then(() => {
              this.getData()
              this.leveldialog = false
              this.lvform.level1 = ''
              this.lvform.name = ''

            })
          } else {
            this.$alert(res.data.errmsg)
          }
        })
      },
      addTask () {
        this.$prompt('请输入任务名称', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
          inputErrorMessage: '任务名称不能为空',
          customClass: 'customClass',
        }).then(({value}) => {
          plansService.create({name: value}).then(res => {
            this.$emit('update')
            this.$message({
              type: 'success',
              message: '创建成功'
            })
          })
        }).catch(() => {
          this.$message('您已取消此次添加')
        })
      },
      handleCurrentChange (val) {
        this.currentPage = val
        this.currentPage1 = val
        this.currentPage2 = val
        this.parent.getData(val-1)
      },
      handleSizeChange (val) {
        this.parent.getData(val-1)
      },
      manipulate (param) {
        if (param.action == 'edit') {
          this.$prompt('请输入任务名称', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
            inputErrorMessage: '任务名称不能为空',
            inputValue: param.data.name,
            customClass: 'customClass',
          }).then(({value}) => {
            plansService.update({name: value, id: param.data.id, createTime: param.data.createTime}).then(res => {
              this.$emit('update')
              this.$message({
                type: 'success',
                message: '修改成功'
              })
            })
          }).catch(() => {
            this.$message('您已取消此次编辑')
          })
        } else if (param.action == 'del') {
          plansService.delete(param.data.id).then(res => {
            this.$emit('update')
            this.$message({
              type: 'success',
              message: '删除成功'
            })
          })
        }
      },
    }
  }
</script>

<style scoped lang="scss" src="../Dcustom.scss"></style>
